require 'enum'

if class == nil then require 'class' end
require 'util'

if Card == nil then Card = class({}) end

function Card:constructor(o, suit, faceUp)
    if type(o) == "number" then
        self.rank = o
        self.suit = suit
        self.faceUp = faceUp
    elseif type( o ) == "table" then
        self.rank = o.rank
        self.suit = o.suit
        self.faceUp = o.faceUp
    end
    self.highlight = false
end

 -- static function
function Card:RankToString (rank)
    if rank == nil then error("invalid rank", 2) rank = 2 end
    if rank > 10 and rank <= 14 then
        return string.sub(TableFindKey( RANK, rank),1,1)
    elseif rank >= 2 then
        return rank
    end
end

function Card:SuitToString (suit)
    local suits = { "♦", "♣" , "♥" , "♠" }
    return suits[suit]
end

function Card:ToString ()
    -- if self.faceUp then
        return  Card:SuitToString( self.suit ) .. Card:RankToString(self.rank)
    -- else
        -- return "The card is facedown, you cannot see it!"
    -- end
end

function Card:GetImageFromFile()
    print(  "Not Implementation Error" )
end

function Card:FaceUp(value)
    self.faceUp = value
    -- print(self.__getclass__())
    self:GetImageFromFile()
    return self.faceUp
end

function Card:Highlight()
    if not self.faceUp then
        return
    end
    self.highlight = true
    if self.image == nil then
        self.image = self:GetImageFromFile()
    end
    print(  'image high light not implemented yet' )
end

function Card:UnHighlight()
    if not self.faceUp then return end
    self.highlight = false
    self:GetImageFromFile()
end

function Card:IsHighlight()
    return self.highlight
end

function Card:IsEqual( card )
    return self:IsRankEqual( card ) and self:IsSuitEqual( card )
end

function Card:IsRankEqual( card )
    return self:GetRank() == card:GetRank()
end

function Card:IsSuitEqual( card )
    return self:GetSuit() == card:GetSuit()
end

-- getters & setters
function Card:GetRank()
    return self.rank
end

function Card:SetRank()
    self.rank = rank
end

function Card:GetSuit()
    return self.suit
end

function Card:SetSuit()
    self.suit = suit
end

function Card:SetCard(rank, suit )
    self.rank = rank
    self.suit = suit
end
